<template>
    <div id="brothers">
        <p>兄弟组件</p>
        <input v-model="valueBrothers" @change="changeValue()" type="text">
    </div>
</template>
<script>
import bus from "./bus.js";
export default {
  name: "brothers",
  components: {},
  data() {
    return {
      valueBrothers: ""
    };
  },
  methods: {
    changeValue() {
      bus.$emit("value", this.valueBrothers);
    }
  },
  beforeCreate() {
    console.log(bus);

    //为了尽快收到消息，写在钩子函数最开始
    bus.$on("value", e => {
      this.valueBrothers = e;
      console.log("兄弟层组件接收到值");
    });
  },
  beforeDestroy() {
    bus.$off();
  }
};
</script>
<style scoped>
</style>